<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text">
<input type="button" value="平方" onclick="f()">
<div></div>


<script>
    function f() {
        let d = document.querySelector("div");
        let i = document.querySelector("input");
        if (isNaN(i.value)) {//判断如果输入的不是数字则进行提示
            d.innerText = "输入错误!";
            return; //方法结束
        }
        //字符串进行 -*/ 运算时会自动转换成数值
        //d.innerText = i.value*1*i.value*1;
        d.innerText = i.value*1+i.value*1;
    }
</script>
</body>
</html>